public class PrimeNumbers {
 public static void main(String[] args) {
 int count = 0;
 long startTime = System.currentTimeMillis();
 
 for (int i = 2; i <= 20000; i++) {
 if (isPrime(i)) {
 System.out.print(i + "\t");
 count++;
 if (count % 5 == 0) {
 System.out.println();
 }
 }
 }
 
 long endTime = System.currentTimeMillis();
 System.out.println("\ntotal:" + (endTime - startTime) + "ms");

 }
 

 public static boolean isPrime(int n) {
 if (n <= 1) return false;
 if (n == 2) return true;
 if (n % 2 == 0) return false;
 for (int i = 3; i <= Math.sqrt(n); i += 2) {
 if (n % i == 0) {
 return false;
 }
 }
 return true;
 }
}